package com.hope.androidproject;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.hope.androidproject.login.LoginActivity;


public class FirstActivity extends Activity {

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                    SharedPreferences preferences = getSharedPreferences("data", MODE_PRIVATE);
                    boolean isFirst = preferences.getBoolean("isFirst", true);
                    Intent it = new Intent();
                    if (isFirst) {
                        it.setClass(FirstActivity.this, GuideActivity.class);
                    } else {
                        if (preferences.getBoolean("isLogin", false)) {
                            it.setClass(FirstActivity.this, MainActivity.class);
                        } else {
                            it.setClass(FirstActivity.this, LoginActivity.class);
                        }
                    }
                    startActivity(it);
                    finish();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }
}
